package com.matt.controller.web.courseV2;

import com.matt.commons.model.StatusResponse;
import com.matt.commons.page.PagerQuery;
import com.matt.domain.courseV2.ChildrenMonthRecord;
import com.matt.domain.courseV2.po.ChildrenMonthInfoPO;
import com.matt.domain.courseV2.vo.ChildrenMonthRecordVO;
import com.matt.service.courseV2.ChildrenMonthRecordService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.matt.foundation.constant.RequestConstant.TICKET;


@RestController
@RequestMapping("/api/children_month_record")
@Slf4j
@Api(tags = "学生 - 月报")
public class ChildrenMonthRecordController {

    @Autowired
    private ChildrenMonthRecordService childrenMonthRecordService;


    @ApiOperation(value = "学生月模板信息")
    @PostMapping("/children_info")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "childrenId", value = "宝宝ID", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "month", value = "月", required = true, dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 000000, message = "successful", response = ChildrenMonthInfoPO.class),
    })
    public StatusResponse childrenInfo(@RequestHeader(TICKET) String ticket, String childrenId, Integer month) {
        ChildrenMonthInfoPO po = childrenMonthRecordService.childrenInfo( childrenId,month);
        return StatusResponse.success(po);
    }


    @ApiOperation(value = "添加")
    @PostMapping("/add")
    @ApiResponses({
            @ApiResponse(code = 000000, message = "successful", response = ChildrenMonthRecord.class),
    })
    public StatusResponse childrenInfo(@RequestHeader(TICKET) String ticket,ChildrenMonthRecord childrenMonthRecord) {
        ChildrenMonthRecord childrenMonthRecord1 = childrenMonthRecordService.addRecord(  ticket ,childrenMonthRecord);
        return StatusResponse.success(childrenMonthRecord1);
    }


    @ApiOperation(value = "查询")
    @PostMapping("/get")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "childrenId", value = "宝宝ID", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "month", value = "月", required = true, dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 000000, message = "successful", response = ChildrenMonthInfoPO.class),
    })
    public StatusResponse get(@RequestHeader(TICKET) String ticket,String childrenId,Integer month) {
        ChildrenMonthRecord childrenMonthRecord1 = childrenMonthRecordService.get( childrenId,month);
        return StatusResponse.success(childrenMonthRecord1);
    }

    @ApiOperation(value = "查询")
    @PostMapping("/getId")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "记录ID", required = true, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code = 000000, message = "successful", response = ChildrenMonthInfoPO.class),
    })
    public StatusResponse getId(@RequestHeader(TICKET) String ticket,String id) {
        ChildrenMonthRecord childrenMonthRecord1 = childrenMonthRecordService.getId( id);
        return StatusResponse.success(childrenMonthRecord1);
    }

    @ApiOperation(value = "查询列表")
    @PostMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "childrenId", value = "宝宝ID", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "month", value = "月", required = false, dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 000000, message = "successful", response = ChildrenMonthRecordVO.class),
    })
    public StatusResponse list(@RequestHeader(TICKET) String ticket,String childrenId,Integer month,String classId,String name, PagerQuery pagerQuery ) {
        Page<ChildrenMonthRecordVO> childrenMonthRecord1 = childrenMonthRecordService.getList(ticket, childrenId,month,classId,name,pagerQuery);
        return StatusResponse.success(childrenMonthRecord1);
    }




    @ApiOperation(value = "查询列表")
    @PostMapping("/list1")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "childrenId", value = "宝宝ID", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "month", value = "月", required = false, dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 000000, message = "successful", response = ChildrenMonthRecordVO.class),
    })
    public StatusResponse list1(String areaId,String childrenId,Integer month,String classId,String name, PagerQuery pagerQuery ) {
        Page<ChildrenMonthRecordVO> childrenMonthRecord1 = childrenMonthRecordService.getList1(areaId,childrenId,month,classId,name,pagerQuery);
        return StatusResponse.success(childrenMonthRecord1);
    }





    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "记录ID", required = true, dataType = "string"),
    })
    public StatusResponse delete(@RequestHeader(TICKET) String ticket,String id) {
        ChildrenMonthRecord childrenMonthRecord = childrenMonthRecordService.getId( id);
        childrenMonthRecord.setDeleted(false);
        ChildrenMonthRecord childrenMonthRecord1 = childrenMonthRecordService.update(  childrenMonthRecord);
        return StatusResponse.success("删除成功");
    }
}
